<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>注册</title>
<link href="css/base.css" rel="stylesheet" type="text/css">
<link href="css/css.css" rel="stylesheet" type="text/css">
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/common_js.js"></script>
    <style>
        .loginPage {
            background-image: url(images/login_bg.jpg);
            background-repeat: no-repeat;
            background-position: center center;
            background-attachment: fixed;
            background-size: cover;
        }
    </style>
</head>

<body class="loginPage ">
<div class="login-top">
    <div class="wrapper">
        <div class="fl font30"><img src="images/logo.jpg" style=""/></div>
        <div class="fr">您好，欢迎使用云钢管理平台！</div>
    </div>
</div>
<div class="l_main">
    <div class="loginbox fl">
        <div class="conlist">
            <div class="conbox" style="display:block;">
                <p>
                    <input type="text" class="loginusername username" placeholder="用户名">
                </p>
                <p>
                    <input type="password" class="loginusername psw" placeholder="密码">
                </p>
                <p>
                    <input type="text" class="loginusername cellphone" placeholder="手机号">
                </p>
                <p>
                    <input type="button" class="captchaBtn" value="获取验证码">
                </p>
                <p>
                    <input type="text" class="loginusername captcha" placeholder="验证码">
                </p>

                <p><span class="fl fntz14 margin-t10"><a href="login.html" style="color:#ff6000">已有账号？立即登录</a></span><span class="fr fntz12 margin-t10">
                    <!--<a href="#">忘记密码？</a>-->
                </span></p>
                <p>
                    <input type="button" class="loginbtn" value="注  册">
                </p>
            </div>
        </div>
    </div>
    <div class="fr margin-r100 margin-t45"><img src="images/login-pic.jpg" width="507" height="325"></div>
</div>
<script>
    //获取验证码
    $('.captchaBtn').on('click',function () {
        var cellphone = $('.cellphone').val()

        if(!(/^1[3-9][0-9]\d{4,8}$/.test(cellphone))){
            alert('请输入合法的手机号')
            return;
        }

        $.ajax({
            url:  DATA_API_HOST+ '/captcha/1000/'+cellphone,
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            //data:JSON.stringify(data),
            success: function (data) {
                if(typeof data === "string"){
                    data = JSON.parse(data);
                }

                alert(data.msg)

            },
            complete:function (data) {

            }
        });

    })

    $('.loginbtn').on('click',function () {
        var username = $('.username').val()
        var password = $('.psw').val()
        var cellphone = $('.cellphone').val()
        var captcha = $('.captcha').val()
        var gender = 1
        var data = {
            username:username,
            password:password,
            cellphone: cellphone,
            captcha: captcha,
            gender:gender,
            groupId:3
        }
        $.ajax({
            url:  DATA_API_HOST+ '/authorize/register/',
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            data:JSON.stringify(data),
            success: function (data) {
                if(typeof data === "string"){
                    data = JSON.parse(data);
                }

                if(data.errCode == 0){  //succ
                    window.location.href='login.html';
                }
                else if(data.errcode == 401){  //登录过期
                    window.location.href="login.html"
                }
                else{  //fail
                    alert(data.msg)
                    //dialog.alert(data.msg);
                    return;
                }

            },
            complete:function (data) {

            }
        });
    })
</script>
</body>
</html>
